/**
 * 创建人:  @author huangpeng    
 * 创建时间:  2022年09月25日 17:08
 * 项目名称:  lemon-blog-cloud
 * 文件名称:  BlCommentController
 * 文件描述:  @Description: 评论信息controller
 * 公司名称:  柠檬
 *
 * All rights Reserved, Designed By 柠檬 
 * @Copyright: 2022-2022
 *
 */
package com.lemon.blog.system.controller;

import com.lemon.blog.system.domain.BlComment;
import com.lemon.blog.system.service.BlCommentService;
import com.lemon.common.core.web.controller.BaseController;
import com.lemon.common.core.web.domain.AjaxResult;
import com.lemon.common.core.web.page.TableDataInfo;
import com.lemon.common.log.annotation.Log;
import com.lemon.common.log.enums.BusinessType;
import com.lemon.common.security.annotation.RequiresPermissions;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 包名称：com.lemon.blog.controller
 * 类名称：BlCommentController
 * 类描述：评论信息controller
 * 创建人：@author huangpeng
 * 创建时间：2022年09月25日 17:08
 */
@Api("评论管理")
@RestController
@RequestMapping("/comment")
public class BlCommentController extends BaseController {

    @Autowired
    private BlCommentService commentService;

    /**
     * 获取博客列表
     * @Title: list
     * @Description: 获取博客列表
     * @param comment
     * @return: TableDataInfo
     * @throws:
     * @author: huangpeng
     * @Date: 2022/9/25 17:28
     */
    @RequiresPermissions("blog:comment:list")
    @GetMapping("/list")
    public TableDataInfo list(BlComment comment) {
        startPage();
        List<BlComment> list = commentService.selectCommentList(comment);
        return getDataTable(list);
    }

    /**
     * 添加评论
     * @Title: add
     * @Description: 添加评论
     * @param comment
     * @return: AjaxResult
     * @throws:
     * @author: huangpeng
     * @Date: 2022/9/25 18:11
     */
    @RequiresPermissions("blog:comment:add")
    @Log(title = "评论管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody BlComment comment) {
        return toAjax(commentService.insert(comment));
    }

    /**
     * 更新评论
     * @Title: edit
     * @Description: 更新评论
     * @param comment
     * @return: AjaxResult
     * @throws:
     * @author: huangpeng
     * @Date: 2022/9/25 22:13
     */
    @RequiresPermissions("blog:comment:edit")
    @Log(title = "评论管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody BlComment comment) {
        return toAjax(commentService.update(comment));
    }

    /**
     * 批量删除
     * @Title: remove
     * @Description: 批量删除
     * @param ids
     * @return: AjaxResult
     * @throws:
     * @author: huangpeng
     * @Date: 2022/9/25 22:29
     */
    @RequiresPermissions("blog:comment:remove")
    @Log(title = "评论管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(commentService.deleteByBatch(ids));
    }

    /**
     * 批量新增评论
     * @Title: insertByBatch
     * @Description: 批量新增评论
     * @param commentList
     * @return: AjaxResult
     * @throws:
     * @author: huangpeng
     * @Date: 2022/11/26 11:52
     */
    @RequiresPermissions("blog:comment:add")
    @Log(title = "评论管理", businessType = BusinessType.INSERT)
    @PostMapping("/insertByBatch")
    public AjaxResult insertByBatch(@RequestBody List<BlComment> commentList) {
        return toAjax(commentService.insertByBatch(commentList));
    }

}
